package com.uchengwang.ui.cm_ui.me.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.uchengwang.R;
import com.uchengwang.ui.cm_ui.me.bean.RefuseBean;
import com.zhy.autolayout.utils.AutoUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by U城网 on 2017/11/1.
 */

public class RefuseAdapter extends RecyclerView.Adapter<RefuseAdapter.RefuseVH>{
    private Context context;
    private List<RefuseBean> list = new ArrayList<>();

    public RefuseAdapter(Context context, List<RefuseBean> list){
        this.context = context;
        this.list = list;
    }

    public List<RefuseBean> getData(){
        return list;
    }

    @Override
    public RefuseVH onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.view_refuse_item, parent, false);
        return new RefuseVH(view);
    }

    @Override
    public void onBindViewHolder(RefuseVH holder, int position) {
        final RefuseBean bean = list.get(position);

        holder.refuse_tv.setText(bean.getTitle());

        if (bean.isCheck()){
            holder.refuse_image.setVisibility(View.VISIBLE);
        }else {
            holder.refuse_image.setVisibility(View.GONE);
        }

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!bean.isCheck()){
                    for (RefuseBean b : list ){
                        b.setCheck(false);
                    }
                    bean.setCheck(true);
                    notifyDataSetChanged();
                }
            }
        });

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class RefuseVH extends RecyclerView.ViewHolder {
        private View itemView;
        private TextView refuse_tv;
        private ImageView refuse_image;

        public RefuseVH(View view) {
            super(view);
            itemView = view;

            AutoUtils.autoSize(view);

            refuse_tv = (TextView) view.findViewById(R.id.refuse_tv);
            refuse_image = (ImageView) view.findViewById(R.id.refuse_image);


        }
    }
}
